import logging
import sys
from flask import Flask

from controller.modeController import model_bp
from logger import setup_logging, logFilePath

app = Flask(__name__)
logger = logging.getLogger(__name__)

def main():
    # 从环境变量中读取端口号
    port = int(sys.argv[1] if len(sys.argv)>=2 else 5000)
    # 从命令行参数中读取debug模式
    debug= bool(int(sys.argv[2] if len(sys.argv)>=3 else 1))
    #logfile路径
    logfile=logFilePath(sys.argv[3] if len(sys.argv) >= 4 else 'logs')

    setup_logging(logfile)

    # 注册蓝图
    app.register_blueprint(model_bp)
    logging.info(f"Starting Flask app on port {port} in debug={debug} mode")
    # 启动Flask应用
    app.run(port=port, debug=debug)

if __name__ == '__main__':
    main()
